package com.echo.register.hosp.api;

import com.echo.register.common.result.Result;
import com.echo.register.hosp.service.DepartmentService;
import com.echo.register.hosp.service.HospitalService;
import com.echo.register.hosp.service.HospitalSetService;
import com.echo.register.hosp.service.ScheduleService;
import com.echo.register.model.hosp.Hospital;
import com.echo.register.model.hosp.Schedule;
import com.echo.register.vo.hosp.DepartmentVo;
import com.echo.register.vo.hosp.HospitalQueryVo;
import com.echo.register.vo.hosp.ScheduleOrderVo;
import com.echo.register.vo.order.SignInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @ClassName: HospitalApiController
 * @Package: com.echo.register.hosp.controller
 * @Description:
 * @Author 谢同学
 * @Create 2023/12/25 19:57
 * @Version 1.0
 */
@Api(tags = "医院管理接口")
@RestController
@RequestMapping("/api/hosp/hospital")
public class HospitalApiController {

    @Autowired
    private HospitalService hospitalService;
    @Autowired
    private DepartmentService departmentService;
    @Autowired
    private ScheduleService scheduleService;
    @Autowired
    private HospitalSetService hospitalSetService;

    @ApiOperation(value = "获取医院分页列表")
    @GetMapping("/{page}/{limit}")
    public Result<Page<Hospital>> getPageList(@PathVariable Integer page,
                                              @PathVariable Integer limit,
                                              HospitalQueryVo hospitalQueryVo) {

        //hospitalQueryVo.setStatus(1); // 显示上线的医院
        Page<Hospital> pageModel = hospitalService.selectPage(page, limit, hospitalQueryVo);
        return Result.ok(pageModel);
    }

    @ApiOperation("根据医院名称模糊查询医院列表")
    @GetMapping("/findByHosname/{hosname}")
    public Result<List<Hospital>> findHospitalByHosnameLike(@PathVariable String hosname) {
        return Result.ok(hospitalService.findHospitalByHosnameLike(hosname));
    }

    @ApiOperation("获取科室列表")
    @GetMapping("/department/{hoscode}")
    public Result<List<DepartmentVo>> getDepartmentList(@PathVariable String hoscode) {
        return Result.ok(departmentService.findDeptTree(hoscode));
    }

    @ApiOperation("获取医院详情")
    @GetMapping("{hoscode}")
    public Result<Map<String, Object>> getHospitalByHoscode(@PathVariable String hoscode) {
        return Result.ok(hospitalService.item(hoscode));
    }

    @ApiOperation(value = "获取可预约排班数据")
    @GetMapping("/auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public Result getBookingSchedule(@PathVariable Integer page,
                                     @PathVariable Integer limit,
                                     @PathVariable String hoscode,
                                     @PathVariable String depcode) {
        return Result.ok(scheduleService.getBookingScheduleRule(page, limit, hoscode, depcode));
    }

    @ApiOperation(value = "获取某天的排班数据")
    @GetMapping("/auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public Result findScheduleList(@PathVariable String hoscode,
                                   @PathVariable String depcode,
                                   @PathVariable String workDate) {
        return Result.ok(scheduleService.getScheduleByHoscodeAndDepcodeAndWorkDate(hoscode, depcode, workDate));
    }

    @ApiOperation(value = "根据排班id获取排班数据")
    @GetMapping("/getSchedule/{scheduleId}")
    public Result<Schedule> getSchedule(@PathVariable String scheduleId) {
        return Result.ok(scheduleService.getById(scheduleId));
    }

    @ApiOperation(value = "根据排班id获取预约下单数据")
    @GetMapping("inner/getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(@PathVariable("scheduleId") String scheduleId) {
        return scheduleService.gerScheduleOrder(scheduleId);
    }

    @ApiOperation(value = "获取签名信息")
    @GetMapping("/inner/getSignInfoVo/{hoscode}")
    public SignInfoVo getSingKeyOrder(@PathVariable String hoscode){
        return hospitalSetService.getSingKeyOrder(hoscode);
    }
}



